import toHash from 'tohash'

export const BASE_URL = import.meta.env.VITE_BASE_URL
export enum REQUEST_CODE {
  success = 'ok',
  badRequest = 'BadRequest',
  forbidden = 'Forbidden', // 密码错误
  unauthorized = 'Unauthorized', // 需要输入密码
  captchaRequired = 'CaptchaRequired', // 需要验证码
  captchaFail = 'CaptchaFail', // 验证码错误
  notFound = 'NotFound',  // 数据不存在
  conflict = 'Conflict', // 内容已过期
  internalServerError = 'InternalServerError', // 服务器异常
  serviceUnavailable = 'ServiceUnavailable' // 服务不可用
}

export const RECAPTCHA_KEY = '6LfTuxMdAAAAAEKL33qpu5sctVnkHfD7yrcdjkxr'

export enum RECAPTCHA_ACTION {
  post='postCreate',
  get='postGet'
}

export const EXPIRE_AT: Array<EnumObj<keyof EXPIRE>> = [
  {
    name: '一小时',
    value: 'hour'
  },
  {
    name: '一天',
    value: 'day'
  },
  {
    name: '一周',
    value: 'week'
  },
  {
    name: '一月',
    value: 'moth'
  },
  {
    name: '一年',
    value: 'year'
  },
  {
    name: '永不过期',
    value: 'never'
  },
]

type EXPIRE = {
  never: string
  year: string
  moth: string
  week: string
  day: string
  hour: string
}

export interface EnumObj<T>{
  name: string
  value: T
}
export const EXPIRE_AT_HASH = toHash<EnumObj<keyof EXPIRE>, EXPIRE>(EXPIRE_AT, 'value')
